package com.greensam.pixelengine.exception;

import com.greensam.pixelengine.pojo.emuns.ErrorCodeEnum;

/**
 * @author Macro_Ray
 * @since 2025/6/13 13:53
 */
public class ThrowUtils {

    /**
     * 封装的条件抛异常
     *
     * @param condition        条件
     * @param runtimeException 异常
     * @author Macro_Ray
     * @since 2025/6/13
     */

    public static void throwIf(boolean condition, RuntimeException runtimeException) {
        if (condition) {
            throw runtimeException;
        }
    }

    /**
     * 封装的条件抛异常
     *
     * @param condition 条件
     * @param resultCode 结果码
     * @author Macro_Ray
     * @since 2025/6/13
     */
    public static void throwIf(boolean condition, ResultCode resultCode) {
        throwIf(condition, new BusinessException(resultCode));
    }

    /**
     * 封装的条件抛异常
     *
     * @param condition 条件
     * @param resultCode 结果码
     * @param message   错误信息
     * @author Macro_Ray
     * @since 2025/6/13
     */
    public static void throwIf(boolean condition, ResultCode resultCode, String message) {
        throwIf(condition, new BusinessException(resultCode, message));
    }

    /**
     * 封装的条件抛异常
     *
     * @param condition 条件
     * @param errorCode 错误码
     * @author Macro_Ray
     * @since 2025/6/17
     */
    public static void throwIf(boolean condition, ErrorCodeEnum errorCode) {
        throwIf(condition, new BusinessException(errorCode));
    }

    /**
     * 封装的条件抛异常
     *
     * @param condition 条件
     * @param errorCode 错误码
     * @param message   错误信息
     * @author Macro_Ray
     * @since 2025/6/17
     */
    public static void throwIf(boolean condition, ErrorCodeEnum errorCode, String message) {
        throwIf(condition, new BusinessException(errorCode, message));
    }
}
